package Interfaz;

import Controladores.*;
import Interfaz.*;
import java.awt.List;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Adrian
 */
public class VentanaMesas extends Ventana_Defaults {

    /**
     * Creates new form Reservaciones
     */
    Mesa m;
    ResultSet rs;
    Orden orden;
    public VentanaMesas() {
            initComponents();
            m = new Mesa();
            setSize(700, 700);
            orden = new Orden();
            setLocationRelativeTo(null);
            setResizable(false);
            setTitle("Agregar Mesa");
            fillComboBox();
            
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnPagar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        btnAtras1 = new javax.swing.JButton();
        cmbMesas = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        lblP2 = new javax.swing.JLabel();
        lblP1 = new javax.swing.JLabel();
        lbl4 = new javax.swing.JLabel();
        lbl2 = new javax.swing.JLabel();
        lbl3 = new javax.swing.JLabel();
        lblP3 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        lbl$4 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        lbl5 = new javax.swing.JLabel();
        lbl1 = new javax.swing.JLabel();
        lblP4 = new javax.swing.JLabel();
        txtTotal = new javax.swing.JTextField();
        cmdActualizar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtComentarios = new javax.swing.JTextArea();
        lblP5 = new javax.swing.JLabel();
        lbl$6 = new javax.swing.JLabel();
        lbl$ = new javax.swing.JLabel();
        lbl$1 = new javax.swing.JLabel();
        lbl$8 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setAlwaysOnTop(true);
        getContentPane().setLayout(null);

        btnPagar.setFont(new java.awt.Font("AR CENA", 0, 18)); // NOI18N
        btnPagar.setText("Pagar");
        btnPagar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPagarActionPerformed(evt);
            }
        });
        getContentPane().add(btnPagar);
        btnPagar.setBounds(400, 440, 120, 33);

        jLabel1.setFont(new java.awt.Font("AR CENA", 0, 18)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Numero de Mesa");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(60, 60, 140, 24);

        btnAtras1.setFont(new java.awt.Font("AR CENA", 0, 14)); // NOI18N
        btnAtras1.setText("Atras");
        btnAtras1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAtras1ActionPerformed(evt);
            }
        });
        getContentPane().add(btnAtras1);
        btnAtras1.setBounds(20, 20, 73, 23);
        getContentPane().add(cmbMesas);
        cmbMesas.setBounds(220, 60, 120, 20);

        jLabel3.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
        jLabel3.setText("Platillo 3");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(50, 270, 70, 16);

        jLabel10.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14)); // NOI18N
        jLabel10.setForeground(new java.awt.Color(255, 255, 255));
        jLabel10.setText("Platillo 2");
        getContentPane().add(jLabel10);
        jLabel10.setBounds(50, 240, 70, 16);

        jLabel11.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14)); // NOI18N
        jLabel11.setForeground(new java.awt.Color(255, 255, 255));
        jLabel11.setText("Platillo 4");
        getContentPane().add(jLabel11);
        jLabel11.setBounds(50, 310, 70, 16);

        jLabel12.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14)); // NOI18N
        jLabel12.setForeground(new java.awt.Color(255, 255, 255));
        jLabel12.setText("Platillo 5");
        getContentPane().add(jLabel12);
        jLabel12.setBounds(50, 350, 70, 16);

        lblP2.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14)); // NOI18N
        lblP2.setForeground(new java.awt.Color(255, 255, 255));
        lblP2.setText("69");
        getContentPane().add(lblP2);
        lblP2.setBounds(320, 240, 70, 20);

        lblP1.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14)); // NOI18N
        lblP1.setForeground(new java.awt.Color(255, 255, 255));
        lblP1.setText("60");
        getContentPane().add(lblP1);
        lblP1.setBounds(320, 200, 70, 16);

        lbl4.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14)); // NOI18N
        lbl4.setForeground(new java.awt.Color(255, 255, 255));
        lbl4.setText("Cantidad");
        getContentPane().add(lbl4);
        lbl4.setBounds(180, 310, 70, 16);

        lbl2.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14)); // NOI18N
        lbl2.setForeground(new java.awt.Color(255, 255, 255));
        lbl2.setText("Cantidad");
        getContentPane().add(lbl2);
        lbl2.setBounds(180, 240, 70, 16);

        lbl3.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14)); // NOI18N
        lbl3.setForeground(new java.awt.Color(255, 255, 255));
        lbl3.setText("Cantidad");
        getContentPane().add(lbl3);
        lbl3.setBounds(180, 270, 70, 16);

        lblP3.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14)); // NOI18N
        lblP3.setForeground(new java.awt.Color(255, 255, 255));
        lblP3.setText("40");
        getContentPane().add(lblP3);
        lblP3.setBounds(320, 270, 70, 16);

        jLabel21.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14)); // NOI18N
        jLabel21.setForeground(new java.awt.Color(255, 255, 255));
        jLabel21.setText("Total:");
        getContentPane().add(jLabel21);
        jLabel21.setBounds(350, 400, 50, 16);

        lbl$4.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14)); // NOI18N
        lbl$4.setForeground(new java.awt.Color(255, 255, 255));
        lbl$4.setText("$");
        getContentPane().add(lbl$4);
        lbl$4.setBounds(300, 310, 10, 16);

        jLabel25.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14)); // NOI18N
        jLabel25.setForeground(new java.awt.Color(255, 255, 255));
        jLabel25.setText("Platillo 1");
        getContentPane().add(jLabel25);
        jLabel25.setBounds(50, 200, 70, 16);

        lbl5.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14)); // NOI18N
        lbl5.setForeground(new java.awt.Color(255, 255, 255));
        lbl5.setText("Cantidad");
        getContentPane().add(lbl5);
        lbl5.setBounds(180, 350, 70, 16);

        lbl1.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14)); // NOI18N
        lbl1.setForeground(new java.awt.Color(255, 255, 255));
        lbl1.setText("Cantidad");
        getContentPane().add(lbl1);
        lbl1.setBounds(180, 200, 70, 16);

        lblP4.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14)); // NOI18N
        lblP4.setForeground(new java.awt.Color(255, 255, 255));
        lblP4.setText("75");
        getContentPane().add(lblP4);
        lblP4.setBounds(320, 310, 70, 16);

        txtTotal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtTotalActionPerformed(evt);
            }
        });
        getContentPane().add(txtTotal);
        txtTotal.setBounds(410, 400, 160, 20);

        cmdActualizar.setFont(new java.awt.Font("Microsoft Sans Serif", 0, 18)); // NOI18N
        cmdActualizar.setText("Actualizar Datos");
        cmdActualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdActualizarActionPerformed(evt);
            }
        });
        getContentPane().add(cmdActualizar);
        cmdActualizar.setBounds(380, 50, 170, 30);

        txtComentarios.setColumns(20);
        txtComentarios.setRows(5);
        jScrollPane1.setViewportView(txtComentarios);

        getContentPane().add(jScrollPane1);
        jScrollPane1.setBounds(410, 180, 200, 170);

        lblP5.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14)); // NOI18N
        lblP5.setForeground(new java.awt.Color(255, 255, 255));
        lblP5.setText("100");
        getContentPane().add(lblP5);
        lblP5.setBounds(320, 350, 70, 16);

        lbl$6.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14)); // NOI18N
        lbl$6.setForeground(new java.awt.Color(255, 255, 255));
        lbl$6.setText("$");
        getContentPane().add(lbl$6);
        lbl$6.setBounds(300, 270, 10, 16);

        lbl$.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14)); // NOI18N
        lbl$.setForeground(new java.awt.Color(255, 255, 255));
        lbl$.setText("$");
        getContentPane().add(lbl$);
        lbl$.setBounds(300, 240, 10, 16);

        lbl$1.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14)); // NOI18N
        lbl$1.setForeground(new java.awt.Color(255, 255, 255));
        lbl$1.setText("$");
        getContentPane().add(lbl$1);
        lbl$1.setBounds(300, 200, 10, 16);

        lbl$8.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 14)); // NOI18N
        lbl$8.setForeground(new java.awt.Color(255, 255, 255));
        lbl$8.setText("$");
        getContentPane().add(lbl$8);
        lbl$8.setBounds(310, 350, 10, 16);

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/interior.jpg"))); // NOI18N
        getContentPane().add(jLabel4);
        jLabel4.setBounds(-30, -40, 725, 600);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAtras1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAtras1ActionPerformed
        this.dispose();
    }//GEN-LAST:event_btnAtras1ActionPerformed

    private void btnPagarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPagarActionPerformed
        orden.eliminarOrden(cmbMesas.getSelectedItem().toString());
        JOptionPane.showMessageDialog(this, "Orden pagada correctamente");
        m.desocuparMesa(cmbMesas.getSelectedItem().toString(),1);
        this.dispose();
    }//GEN-LAST:event_btnPagarActionPerformed

    private void cmbMesasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbMesasActionPerformed
        // TODO add your handling code here:
        
        
    }//GEN-LAST:event_cmbMesasActionPerformed

    private void txtTotalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtTotalActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtTotalActionPerformed

    private void cmdActualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdActualizarActionPerformed
        int sumaTotal;
        try {
            
            rs = orden.getOrdenMesa(cmbMesas.getSelectedItem().toString());
            rs.next();
            lbl1.setText(rs.getString("platillo1"));
            lbl2.setText(rs.getString("platillo2"));
            lbl3.setText(rs.getString("platillo3"));
            lbl4.setText(rs.getString("platillo4"));
            lbl5.setText(rs.getString("platillo5"));
            txtComentarios.setText(rs.getString("comentarios"));
        } catch (SQLException ex) {
            Logger.getLogger(VentanaMesas.class.getName()).log(Level.SEVERE, null, ex);
        }
       sumaTotal=(Integer.parseInt(lbl1.getText())*Integer.parseInt(lblP1.getText()));
       sumaTotal+=(Integer.parseInt(lbl2.getText())*Integer.parseInt(lblP2.getText()));
       sumaTotal+=(Integer.parseInt(lbl3.getText())*Integer.parseInt(lblP3.getText()));
       sumaTotal+=(Integer.parseInt(lbl4.getText())*Integer.parseInt(lblP4.getText()));
       sumaTotal+=(Integer.parseInt(lbl5.getText())*Integer.parseInt(lblP5.getText()));
       txtTotal.setText(String.valueOf(sumaTotal));
    }//GEN-LAST:event_cmdActualizarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(VentanaMesas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(VentanaMesas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(VentanaMesas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(VentanaMesas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VentanaMesas().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAtras1;
    private javax.swing.JButton btnPagar;
    private javax.swing.JComboBox cmbMesas;
    private javax.swing.JButton cmdActualizar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lbl$;
    private javax.swing.JLabel lbl$1;
    private javax.swing.JLabel lbl$4;
    private javax.swing.JLabel lbl$6;
    private javax.swing.JLabel lbl$8;
    private javax.swing.JLabel lbl1;
    private javax.swing.JLabel lbl2;
    private javax.swing.JLabel lbl3;
    private javax.swing.JLabel lbl4;
    private javax.swing.JLabel lbl5;
    private javax.swing.JLabel lblP1;
    private javax.swing.JLabel lblP2;
    private javax.swing.JLabel lblP3;
    private javax.swing.JLabel lblP4;
    private javax.swing.JLabel lblP5;
    private javax.swing.JTextArea txtComentarios;
    private javax.swing.JTextField txtTotal;
    // End of variables declaration//GEN-END:variables
private void fillComboBox(){
        ArrayList<String> mesas = (ArrayList<String>) m.getIdMesaList();
        if(mesas!=null){
        mesas.stream().forEach((s) -> {
            cmbMesas.addItem(s);
        });
        }else {
            JOptionPane.showMessageDialog(this, "No existen mesas con ordenes");
            this.dispose();
        }
}

}
